//
//  serviceInterfaceTemplate.h
//  aliAlbum
//
//  Created by xugaoqiang on 11-9-22.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIHTTPRequestDelegate.h"
#import "ASIFormDataRequest.h"
#import "ASIHTTPRequest.h"
#import "JSONKit.h"

#define SERVICE_FAIL @"0"
#define SERVICE_SUCCESS @"1"
#define SERVICE_TIMEOUT @"2"
#define SERVICE_CONNECTIONFAIL @"3"

#define kTimeOutDuration 5

@protocol serviceInterfaceTemplateDelegate<NSObject>
@required
- (NSURL*)targetURL;
- (void)passDataOut;
- (void)configureRequest;
@end

typedef enum _requestMode
{
	Request_Mode_Synchronous = 0,
	Request_Mode_Asynchronous,
}TRequestMode;

@class ASIFormDataRequest;
@interface serviceInterfaceTemplate : NSObject
<ASIHTTPRequestDelegate>
{
	ASIFormDataRequest *m_request;
	
	// service identity
	NSInteger m_identity;
	
	// send data
	NSDictionary *m_dicSendData;
	
	// callBack data
	NSMutableDictionary *m_dicReceiveData;
	
	// Request mode
	TRequestMode m_requestMode;
	
	BOOL m_bEmptyDB;
}

@property (nonatomic, retain) ASIFormDataRequest *m_request;
@property (nonatomic, retain) NSDictionary *m_dicSendData;
@property (nonatomic, retain) NSMutableDictionary *m_dicReceiveData;
@property (nonatomic, assign) NSInteger m_identity;
@property (nonatomic, retain) NSObject* m_serviceHandler;

-(void)sendRequest:(NSDictionary*)aDic;
-(void)clearData;
-(void)setRequestMode:(TRequestMode)mode;

-(void)allOver;
@end

@interface serviceInterfaceTemplate(Private)
- (void) send;
- (NSData*)encryptBodyData:(NSData*)bodyData;
- (void)parseResponseData:(NSData*)data;
- (void)passDataOut;
- (NSURL*)targetURL;
- (void)configureRequest;
- (void)requestDidFailed;
@end